/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.epsi.blokus.entity;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;
import org.epsi.blokus.tools.*;

/**
 * Affichage d'une pièce sur le plateau
 * @author julien.lafont
 */
public class Piece implements IEntity, IConstantes {

    

    private static Image pieceBleu = null;
    private static Image pieceRouge = null;
    private static Image pieceSelect = null;
    private static Image pieceDeny = null;
    
    private float x;
    private float y;
    private TTypePiece type;


    public Piece(TTypePiece couleur, float x, float y) throws SlickException
    {
        // Charger en mémoire les images
        if (pieceBleu == null || pieceRouge == null)
        {
            pieceBleu = new Image("/res/Pieces/hex.blue.png");
            pieceRouge = new Image("/res/Pieces/hex.red.png");
            pieceSelect = new Image("/res/Pieces/hex.select.png");
            pieceDeny = new Image("/res/Pieces/hex.deny.png");
        }
        
        type = couleur;
        this.x = x;
        this.y = y;
    }

    public Piece(TTypePiece couleur, Point coord) throws SlickException
    {
        this(couleur, coord.getX(), coord.getY());
    }

    public void init(GameContainer container, StateBasedGame game) throws SlickException {
               
    }

    public void update(GameContainer container, StateBasedGame game, int delta) throws SlickException {
        
    }

    public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {

        switch(type)
        {
            case Bleu:
                pieceBleu.draw(x-2, y-2);
            break;

            case Rouge:
                pieceRouge.draw(x-2, y-2);
            break;

            case Select:
                pieceSelect.draw(x-2, y-2);
            break;

            case Deny:
                pieceDeny.draw(x-2, y-2);
            break;
        }
    }



    public void setPosition(Point pos)
    {
        this.x = pos.getX();
        this.y = pos.getY();
    }


    public void setType(TTypePiece type)
    {
        this.type = type;
    }

    
}
